package com.whnk.web.controller.rtms;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.rtms.domain.Build;
import com.whnk.rtms.service.IBuildService;

/**
 * 测试代码生成 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-02-26
 */
@Controller
@RequestMapping("/rtms/build")
public class TestBuildController extends BaseController
{
    private String prefix = "rtms/build";
	
	@Autowired
	private IBuildService buildService;
	
	@RequiresPermissions("rtms:build:view")
	@GetMapping()
	public String build()
	{
	    return prefix + "/build";
	}
	
	/**
	 * 查询测试代码生成列表
	 */
	@RequiresPermissions("rtms:build:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Build build)
	{
		startPage();
        List<Build> list = buildService.selectBuildList(build);
		return getDataTable(list);
	}
	
	/**
	 * 新增测试代码生成
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存测试代码生成
	 */
	@RequiresPermissions("rtms:build:add")
	@Log(title = "测试代码生成", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Build build)
	{		
		return toAjax(buildService.insertBuild(build));
	}

	/**
	 * 修改测试代码生成
	 */
	@GetMapping("/edit/{operId}")
	public String edit(@PathVariable("operId") Integer operId, ModelMap mmap)
	{
		Build build = buildService.selectBuildById(operId);
		mmap.put("build", build);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存测试代码生成
	 */
	@RequiresPermissions("rtms:build:edit")
	@Log(title = "测试代码生成", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Build build)
	{		
		return toAjax(buildService.updateBuild(build));
	}
	
	/**
	 * 删除测试代码生成
	 */
	@RequiresPermissions("rtms:build:remove")
	@Log(title = "测试代码生成", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(buildService.deleteBuildByIds(ids));
	}
	
}
